package com.qf.helloworld;

import com.qf.util.ConnectionUtil;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import org.junit.Test;

/**
 * 生产者
 * @author zjw
 */
public class Publisher {
    
    @Test
    public void publish() throws Exception {
        //1. 创建连接对象
        Connection connection = ConnectionUtil.getConnection();

        //2. 构建通道
        Channel channel = connection.openChannel().get();

        //3. 准备消息
        String msg = "Hello RabbitMQ Again！！";
        
        //4. 发送消息
        channel.basicPublish("","hello_queue",null,msg.getBytes());
        System.out.println("ok!!!!");

        //5. 释放资源
        channel.close();
        connection.close();
    }
}
